﻿using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace NTmdb.TestProject
{
    /// <summary>
    ///     This is a test class for TmdbMoviePreviewBaseTest and is intended
    ///     to contain all TmdbMoviePreviewBaseTest Unit Tests
    /// </summary>
    [TestClass]
    public class TmdbMoviePreviewBaseTest
    {
        /// <summary>
        ///     A test for TmdbMoviePreviewBase Constructor
        /// </summary>
        [TestMethod]
        public void TmdbMoviePreviewBaseConstructorTest()
        {
            var target = new TmdbMoviePreviewBase();
            Assert.IsNotNull( target );
        }

        /// <summary>
        ///     A test for Id
        /// </summary>
        [TestMethod]
        public void IdTest()
        {
            var target = new TmdbMoviePreviewBase();
            int expected = new Random().Next( 0, Int32.MaxValue );
            target.Id = expected;
            int actual = target.Id;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for OriginalTitle
        /// </summary>
        [TestMethod]
        public void OriginalTitleTest()
        {
            var target = new TmdbMoviePreviewBase();
            string expected = Guid.NewGuid().ToString();
            target.OriginalTitle = expected;
            string actual = target.OriginalTitle;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for PosterPath
        /// </summary>
        [TestMethod]
        public void PosterPathTest()
        {
            var target = new TmdbMoviePreviewBase();
            string expected = Guid.NewGuid().ToString();
            target.PosterPath = expected;
            string actual = target.PosterPath;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for ReleaseDate
        /// </summary>
        [TestMethod]
        public void ReleaseDateTest()
        {
            var target = new TmdbMoviePreviewBase();
            string expected = Guid.NewGuid().ToString();
            target.ReleaseDate = expected;
            string actual = target.ReleaseDate;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Title
        /// </summary>
        [TestMethod]
        public void TitleTest()
        {
            var target = new TmdbMoviePreviewBase();
            string expected = Guid.NewGuid().ToString();
            target.Title = expected;
            string actual = target.Title;
            Assert.AreEqual( expected, actual );
        }

        /// <summary>
        ///     A test for Serialize & Deserialize
        /// </summary>
        [TestMethod]
        [DeploymentItem( @"..\..\TestData\moviePreviewBase.json.txt" )]
        public async Task SerializeDeserializeTest()
        {
            var target = new TmdbMoviePreviewBase();
            var jsonContent = File.ReadAllText( "moviePreviewBase.json.txt" );
            var actual = await target.DeserializeJson<TmdbMoviePreviewBase>( jsonContent );

            Assert.AreEqual( 68726, actual.Id );
            Assert.AreEqual( "Pacific Rim", actual.OriginalTitle );
            Assert.AreEqual( "/sCJEwEShZvruTpQ2a4yiX3Q9EyZ.jpg", actual.PosterPath );
            Assert.AreEqual( "2013-07-12", actual.ReleaseDate );
            Assert.AreEqual( "Pacific Rim", actual.Title );
        }
    }
}